<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.icode.core.alipay.util.*"%>
<%@ page import="com.icode.core.alipay.config.*"%>
<%@ page import="java.io.UnsupportedEncodingException" %>
<%@ page import="com.icode.core.model.order.ReFund" %>
<%@ page import="com.icode.core.shared.AlipayHandle" %>
<%
    //即时到账退款接口返回通知
    Map<String, String> params = new HashMap<>();
    Map requestParams = request.getParameterMap();
    for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext(); ) {
        String name = (String) iter.next();
        String[] values = (String[]) requestParams.get(name);
        String valueStr = "";
        for (int i = 0; i < values.length; i++) {
            valueStr = (i == values.length - 1) ? valueStr + values[i]
                    : valueStr + values[i] + ",";
        }
        try {
            //乱码解决，这段代码在出现乱码时使用。如果mysign和sign不相等也可以使用这段代码转化
            valueStr = new String(valueStr.getBytes("ISO-8859-1"), "gbk");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        params.put(name, valueStr);
    }

    //获取支付宝的通知返回参数，可参考技术文档中页面跳转同步通知参数列表(以下仅供参考)//
    String batch_no = "";
    String success_num = "";
    String result_details = "";
    try {
        //批次号
        batch_no = new String(request.getParameter("batch_no").getBytes("ISO-8859-1"), "UTF-8");
        //批量退款数据中转账成功的笔数
        success_num = new String(request.getParameter("success_num").getBytes("ISO-8859-1"), "UTF-8");
        //批量退款数据中的详细信息
        result_details = new String(request.getParameter("result_details").getBytes("UTF-8"), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    if (AlipayNotify.verify(params)) {//验证成功
//        ReFund reFund = orderService.findReFundByBatchNo(batch_no);
//        orderService.changeReFundStatusByGuid(reFund.guid(), "已退款");
//        orderService.changeOrderStatusByGuid(reFund.order().guid(), "已退款");
        AlipayHandle.changeStatus();
        out.println("success");
    } else {//验证失败
        out.println("fail");
    }
%>